﻿using System.Text;

namespace EasyXaf.EntityDesigner.Models;

public static class CurrentDomainModelUtils
{
    public static void Save(Guid currentDomainModelId)
    {
        var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CurrentDomainModel.txt");
        File.WriteAllText(file, currentDomainModelId.ToString(), Encoding.UTF8);
    }

    public static Guid? Read()
    {
        var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CurrentDomainModel.txt");
        if (File.Exists(file))
        {
            if (Guid.TryParse(File.ReadAllText(file, Encoding.UTF8), out Guid currentDomainModelId))
            {
                return currentDomainModelId;
            }
        }
        return null;
    }
}
